
// Figure A5

/*
The dataset that is imported contains information on the road link level for
Oslo and Viken, imported from the Norwegian transport model. 
The variables used here are:

- KOLLEKTIVFE: Whether the road link has bus lane
- KAPTID_07_0: Drive time during morning rush
- KAPTID_15_1: Drive time during afternoon rush
- FM_TIME:     Drive time outside rush hours
- DISTANCE:    Length of road link
*/
import dbase using "${datain}\lenker_viken_2020.DBF", clear

gen d_ptl = (KOLLEKTIVFE > 0)
replace d_ptl = . if KOLLEKTIVFE == .

* Avg of morning and afternoon rush
gen time_rush = (KAPTID_07_0 + KAPTID_15_1)/2
* Travel time savings in minutes (avg of morning and afternoon rush minus time outside rush)
gen tt_savings = time_rush - FM_TIME
* Measure in minutes per kilometer
replace time_rush = time_rush / DISTANCE
replace tt_savings = tt_savings / DISTANCE
* Relative travel time savings
gen tt_savings_rel = tt_savings * 100 / time_rush
* Weight as length of the road links
gen weight_var = DISTANCE * 1000
	
twoway histogram tt_savings if d_ptl > 0 & d_ptl != . [fw = weight_var], graphregion(color(white)) ///
	width(0.1) ///
	xtitle("Travel time saved (min/km)") lcolor(gs6) fcolor(gs10) ///
	name(ptl1, replace) percent
graph export "${figures}FigureA5a.png", as(png) replace	
graph export "${figures}FigureA5a.pdf", as(pdf) replace	
graph save   "${figures}FigureA5a.gph", replace

twoway histogram tt_savings_rel if d_ptl > 0 & d_ptl != . [fw = weight_var], graphregion(color(white)) ///
	width(2.5) xtitle("Percent of travel time saved") lcolor(gs6) fcolor(gs10) ///
	name(ptl1rel2, replace) percent	
graph export "${figures}FigureA5b.png", as(png) replace	
graph export "${figures}FigureA5b.pdf", as(pdf) replace	
graph save   "${figures}FigureA5b.gph", replace


